<?php
class OffersFactory extends MACFactory{
	
	private static $_instance;
	
	public static function getInstance() {
		if(is_null(self::$_instance)){
			self::$_instance = new OffersFactory();
		}
		return self::$_instance;
	}
	
	
	public function prepareAndSendOffer($offer_id)
	{
		$translator = LanguageFactory::getInstance();
		
		$session = new Zend_Session_Namespace();
		$user = $session->user;

		$tmp = explode("_", $offer_id);
		$id = $tmp[1]; //retrieving offer id
		
		$offerAmount = $translator->getTranslation("SubmissionAmount".$id);
		$offerDesc = $translator->getTranslation("SubmissionOffer".$id);
		
		//following the specified offer, we'll build a different email (I.E. "devis") 
		$this->logger->info("OffersFactory::prepareofferAction > offer_id = $offer_id to $user->email");
				
		
		//formatting email
		$emailObject = $translator->getTranslation("SubmissionRequestObject");
		$emailBody = $translator->getTranslation("SubmissionRequestBody");
		$emailBody = str_replace("%EMAIL%", $user->email, $emailBody);
		$offerContent = $offerAmount.ConfigFactory::getInstance()->getConfig()->application->currency." ".$translator->getTranslation("For")." : ".$offerDesc;
		$emailBody = str_replace("%CONTENT%", $offerContent , $emailBody);
		
		$emailFactory = EmailFactory::getInstance();
		
		return $emailFactory->send($user->email, $emailObject, $emailBody);
	}
}